import { createRouter, createWebHistory } from 'vue-router'
import appStore from '@/store'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/login', component: () => import('@/views/login/LoginPage.vue') }, //登录页
    {
      path: '/',
      component: () => import('@/views/layout/LayoutContainer.vue'),
      redirect: '/program',
      children: [
        {
          path: '/program',
          component: () => import('@/views/program/ProgramPage.vue')
        },
        {
          path: '/register',
          component: () => import('@/views/approval/MyRegister.vue')
        },
        {
          path: '/participant',
          component: () => import('@/views/approval/MyParticipant.vue')
        },
        {
          path: '/info',
          component: () => import('@/views/info/InfoPage.vue')
        }
      ]
    }
  ]
})

//登录拦截
// router.beforeEach((to) => {
//   //没有token，且访问的是登录页，拦截；其他情况放行
//   if (!appStore.useUser.token && to.path !== '/login') return '/login'
// })
export default router
